#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "data.h"

/*
struct bmp_file_info {
  uint16_t color_planes;
  uint16_t color_depth;
  uint32_t compression;
  uint32_t image_size;
  uint32_t horizontal_res;
  uint32_t vertical_res;
  uint32_t colors_per_palette;
  uint32_t important_colors;
};
*/

static void write_bmp_file(char* filename) {
  FILE* fp;
  fp = fopen(filename, "w");
  if (fp == NULL) {
    fprintf(stderr, "Cannot open output file %", filename);
    exit(1);
  }
  uint32_t width = 1;
  uint32_t height = 1;
  uint32_t image_size = width * height * 3 + height * 2;
  uint32_t data_offset = 54;
  uint32_t file_size = image_size + data_offset;

  // 0x00
  uint16_t magic_number = 0x4D42;
  fwrite(&magic_number, 2, 1, fp);
  // 0x02
  fwrite(&file_size, 4, 1, fp);
  // 0x06
  uint16_t reserved_a = 0;
  fwrite(&reserved_a, 2, 1, fp);
  // 0x08
  uint16_t reserved_b = 0;
  fwrite(&reserved_b, 2, 1, fp);
  // 0x0A
  fwrite(&data_offset, 4, 1, fp);
  // 0x0E
  uint32_t header_size = 40;
  fwrite(&header_size, 4, 1, fp);
  // 0x12
  fwrite(&width, 4, 1, fp);
  // 0x16
  fwrite(&height, 4, 1, fp);
  // 0x1A
  uint16_t color_planes = 1;
  fwrite(&color_planes, 2, 1, fp);
  uint16_t color_depth = 32;
  fwrite(&color_depth, 2, 1, fp);
  uint32_t compression = 0;
  fwrite(&compression, 4, 1, fp);
  fwrite(&image_size, 4, 1, fp);
  uint32_t horizontal_res = 1;
  fwrite(&horizontal_res, 4, 1, fp);
  uint32_t vertical_res = 1;
  fwrite(&vertical_res, 4, 1, fp);
  uint32_t colors_per_palette = 0;
  fwrite(&colors_per_palette, 4, 1, fp);
  uint32_t important_colors = 0;
  fwrite(&important_colors, 4, 1, fp);

  uint8_t value = 0xDD;
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
  fwrite(&value, 1, 1, fp);
}

int main (int argc, char* argv[]) {
  printf("Hello World!%d\n", sizeof (uint16_t));
  write_bmp_file("out.bmp");
  return 0;
}

